#include<stdio.h>
#include<string.h>
#define maxn 100
struct Node
{
    char name[35];
    char num[12];
    int index;
};
typedef struct Node Name;
Name name[maxn];
void BubbleSort(Name name[], int len);
int main()
{
    int n;
    scanf("%d", &n);
    int used[n];
    memset(used, 0, sizeof(used));
    for(int i=0;i<n;i++)
    {
        scanf("%s %s\n", name[i].name, name[i].num);
        name[i].index = i;
        for(int j=0;j<i;j++)
        {
            if(strcmp(name[i].name,name[j].name) == 0)
            {
                used[j]++, used[i] = used[j];
                if(strcmp(name[i].num,name[j].num) == 0)
                    name[i].index = -1; //表示重复了，跳过
                else
                    strcat(name[i].name, "_");
                break;             
            }
        }
    }
    BubbleSort(name, n);
    for(int i=0;i<n;i++)
    {
        if(name[i].index != -1)
        {
            printf("%s", name[i].name);
            if(used[name[i].index] > 0 && name[i].name[strlen(name[i].name)-1] == '_')
                printf("%d", used[name[i].index]);
            printf(" %s\n", name[i].num);            
        }
    }
    return 0;
}

void BubbleSort(Name name[], int len)
{
    for(int i=0;i<len;i++)
    {
        for(int j=0;j<len-1-i;j++)
        {
            Name tmp;
            if(strcmp(name[j].name, name[j+1].name) > 0)
            {
                tmp = name[j];
                name[j] = name[j+1];
                name[j+1] = tmp;
            }
        }
    }
}